﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Model.Services;
using Domain.Model.Infractores;
using Domain.Model.Repositories;
using Domain.Model.Aggregates;
using Domain.Model.LicenciasDeConduccion;
using Domain.Model.Direcciones;

namespace Domain.Model.Entidades.Infractors
{
    public class InfractorService: IInfractorService
    {
        /// Referencia al servicio de infractors
        private InfractorRepository infractorRepository;


        //Constructor
        public InfractorService(InfractorRepository infractorRepository)
        {
            if (infractorRepository == null)
            {
                throw new ArgumentNullException("infractorRepository");
            }
            this.infractorRepository = infractorRepository;
        }

        public Infractor InfractorFromId(string infractorId)
        {
            return this.infractorRepository.FromId(new InfractorId(infractorId));
        }

        public InfractorId CreateInfractor(String numIdentificacion, String nombres, String apellidos, String tipoIdentificacion, LicenciaConduccion licenciaDeConduccion, Direccion direccion)
        {
            Infractor newInfractor;
            newInfractor = InfractorAggregate.CreateInfractor((InfractorId)infractorRepository.NextIdentity(), numIdentificacion, nombres, apellidos, tipoIdentificacion, licenciaDeConduccion, direccion);
            this.infractorRepository.Insert(newInfractor);
            return (InfractorId)newInfractor.Identity;
        }


        public List<Infractor> All()
        {
            return this.infractorRepository.All();
        }


        public void RemoveInfractor(InfractorId infractorId)
        {
            this.infractorRepository.Remove(infractorId);
        }


        public InfractorId EditInfractor(InfractorId infractorId, String numIdentificacion, String nombres, String apellidos, String tipoIdentificacion, LicenciaConduccion licenciaDeConduccion, Direccion direccion)
        {
            Infractor newInfractor;
            newInfractor = InfractorAggregate.CreateInfractor(infractorId, numIdentificacion, nombres, apellidos, tipoIdentificacion, licenciaDeConduccion, direccion);
            this.infractorRepository.Update(newInfractor);
            return (InfractorId)newInfractor.Identity;
        }

        public InfractorId FromIdentificacion(string numIdentificacion)
        {
            return infractorRepository.FromIdentificacion(numIdentificacion);
        }
    }
}
